home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / vert_norm / smooth.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  2.6 KB  |  93 lines

  1. /* smooth.h */
  2. /* header file for polygon smoothing */
  3. /* Andrew S. Glassner / Xerox PARC */
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7.  
  8. #ifdef STANDALONE_TEST
  9.  
  10. #define NEWTYPE(x) (x *)malloc((unsigned)(sizeof(x)))
  11.  
  12. typedef struct Point3Struct {
  13.    double x, y, z;
  14.    } Point3;
  15. typedef Point3 Vector3;
  16. typedef int boolean;
  17. #define TRUE  1
  18. #define FALSE 0
  19.  
  20. Vector3 *V3Normalize(Vector3 *v);
  21. Vector3 *V3Add(Vector3 *a, Vector3 *b, Vector3 *c);
  22. double V3Dot(Vector3 *a, Vector3 *b);
  23. #else
  24. #include "GraphicsGems.h"
  25. #endif
  26.  
  27. /********* MACROS and CONSTANTS *********/
  28.  
  29. /* new array creator */
  30. #define NEWA(x, num) (x *)malloc((unsigned)((num) * sizeof(x)))
  31.  
  32. #define MARKWAITING    0
  33. #define MARKWORKING    1
  34. #define MARKDONE       2
  35.  
  36. /* fuzzy comparison macro */
  37. #define FUZZEQ(x,y)  (fabs((x)-(y))<(smooth->fuzz))
  38.  
  39. /* hash table size; related to HASH */
  40. #define HASH_TABLE_SIZE           1000
  41.  
  42. /* quantization increment */
  43. #define QSIZE     1000.0
  44.  
  45. #define QUANT(x)     (((int)((x)*QSIZE))/QSIZE)
  46. #define ABSQUANT(x)  (((int)((fabs(x))*QSIZE))/QSIZE)
  47. #define HASH(pt)     ( \
  48.              (int)(((3*ABSQUANT(pt->x)) + \
  49.                 (5*ABSQUANT(pt->y)) + \
  50.                 (7*ABSQUANT(pt->z))) * \
  51.               HASH_TABLE_SIZE)) % HASH_TABLE_SIZE
  52.  
  53. /********* STRUCTS AND TYPES *********/
  54.  
  55. typedef struct Polygonstruct {
  56.     Point3    *vertices;  /* polygon vertices */
  57.     Vector3    *normals;   /* normal at each vertex */
  58.     Vector3    normal;        /* normal for polygon */
  59.     int        numVerts;   /* number of vertices */
  60.     void    *user;        /* user information */
  61.     struct    Polygonstruct *next;
  62.     } Polygon_def;
  63. typedef Polygon_def *Polygon;
  64.  
  65. typedef struct HashNodestruct {
  66.     Polygon   polygon;        /* polygon for this vertex */
  67.     int          vertexNum;    /* which vertex this is */
  68.     int          marked;        /* vertex status */
  69.     struct    HashNodestruct *next;
  70.     } HashNode_def;
  71. typedef HashNode_def *HashNode;
  72.  
  73. typedef struct SmoothStruct {
  74.     HashNode  hashTable[HASH_TABLE_SIZE];
  75.     Polygon   polygonTable;
  76.     Polygon   polyTail;
  77.     double    fuzz;          /* distance for vertex equality */
  78.     double    fuzzFraction;   /* fraction of model size for fuzz */
  79.     boolean   edgeTest;          /* apply edging test using minDot */
  80.     float     minDot;          /* if > this, make sharp edge; see above */
  81.     } Smooth_def;
  82. typedef Smooth_def *Smooth;
  83.  
  84. /********* public procs ************/
  85. Smooth     initAllTables();
  86. void     includePolygon(int numVerts, Point3 *verts, Smooth smooth, void *user);
  87. void     makeVertexNormals(Smooth smooth);
  88.  
  89. /********* public option contorl procs ************/
  90. void     setFuzzFraction(Smooth smooth, float fuzzFraction);
  91. void     enableEdgePreservation(Smooth smooth, float minDot);
  92. void     disableEdgePreservation(Smooth smooth);
  93.